package h.c.z.designPattern.C01_FactoryPattern.FactoryMethod;

/**
 * [客户端]屌丝升级 有媳妇了-->有钱了，请厨师了
 * @author jinsicao
 *
 */
public class EatWithFactoryMethod {

	public static void main(String[] args) {

		// 想吃红烧肉
		ProductFactory productFactory = new RedMeatProductFactory();
		productFactory.createProduct();
		// 想吃清蒸鱼
		productFactory = new SteamedFishFactory();
		productFactory.createProduct();
		// 想吃土豆丝
		productFactory = new ShreddedPotatoeshFactory();
		productFactory.createProduct();
		
	}

}

/**
 * 工厂方法抽象
 * @author jinsicao
 *
 */
abstract class ProductFactory {
	
	protected abstract Product factoryMethod();
	
	/**
	 * 加工食物
	 * @return
	 */
	public void createProduct() {
		Product product = this.factoryMethod();
		product.createProduct();
	}
}

/**
 * 红烧肉工厂
 * @author jinsicao
 */
class RedMeatProductFactory extends ProductFactory {

	@Override
	protected Product factoryMethod() {
		return new RedMeatProduct();
	}
	
}

/**
 * 清蒸鱼工厂
 * @author jinsicao
 */
class SteamedFishFactory extends ProductFactory {
	
	@Override
	protected Product factoryMethod() {
		return new SteamedFishProduct();
	}
	
}

/**
 * 土豆丝工厂
 * @author jinsicao
 */
class ShreddedPotatoeshFactory extends ProductFactory {
	
	@Override
	protected Product factoryMethod() {
		return new ShreddedPotatoeshProduct();
	}
	
}

/**
 * 获取食物接口
 * @author jinsicao
 */
interface Product {
	
	/**
	 * 加工食物
	 * @return
	 */
	public void createProduct();
}

/**
 * 红烧肉
 * @author jinsicao
 *
 */
class RedMeatProduct implements Product {

	@Override
	public void createProduct() {
		System.out.println("吃红烧肉");
	}
	
}

/**
 * 清蒸鱼
 * @author jinsicao
 *
 */
class SteamedFishProduct implements Product {
	
	@Override
	public void createProduct() {
		System.out.println("吃清蒸鱼");
	}
	
}

/**
 * 土豆丝
 * @author jinsicao
 *
 */
class ShreddedPotatoeshProduct implements Product {
	
	@Override
	public void createProduct() {
		System.out.println("吃土豆丝");
	}
	
}
